package edu.washington.cs.workflow.matching;

import java.util.LinkedList;
import java.util.List;

import com.ibm.wala.ipa.callgraph.CGNode;

import edu.washington.cs.workflow.analysis.AccessedGUIObjectFinder;
import edu.washington.cs.workflow.analysis.GUIObjectInitInfo;
import edu.washington.cs.workflow.util.Utils;

public class CGNodeDifferentior {
	/**
	 * Two corresponding nodes
	 * */
	public final AccessedGUIObjectFinder oldFinder;
	public final AccessedGUIObjectFinder newFinder;
	
	public CGNodeDifferentior(AccessedGUIObjectFinder oldFinder,
			AccessedGUIObjectFinder newFinder) {
		Utils.checkNotNull(oldFinder);
		Utils.checkNotNull(newFinder);
		this.oldFinder = oldFinder;
		this.newFinder = newFinder;
	}
	
	public List<GUIObjectInitInfo> findAddedGUIObjects(String oldMethodSig,
			String newMethodSig) {
		List<GUIObjectInitInfo> oldAccessedObjs = this.oldFinder.findGUIObjects(oldMethodSig);
		List<GUIObjectInitInfo> newAccessedObjs = this.newFinder.findGUIObjects(newMethodSig);
		
		Utils.debugPrintln("old: " + oldAccessedObjs.size());
		Utils.debugPrintln("new: " + newAccessedObjs.size());
		
		List<GUIObjectInitInfo> addedGUIObjs = new LinkedList<GUIObjectInitInfo>();
		for(GUIObjectInitInfo newObj : newAccessedObjs) {
			boolean exist = false;
			for(GUIObjectInitInfo oldObj : oldAccessedObjs) {
				//still not clear on how to compare them
				if(newObj.getObjectInfo().equals(oldObj.getObjectInfo())) {
					exist = true;
				}
			}
			if(!exist) {
				addedGUIObjs.add(newObj);
			}
		}
		
		return addedGUIObjs;
	}
}